﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Persons.Classes;
using Persons.Interfaces;

namespace Persons.Classes
{
    /// <summary>
    /// Класс, реализующий CRUD для спика персон
    /// </summary>
    public class ListOfPersons : List<Persona>,IEnumerable<Persona>
    {
        public static IDS ds = null;
        public ListOfPersons() { }
        public ListOfPersons(IDS _ds)
        {
            ds = _ds;
        }
        public void Create(Persona p)
        {
            ds.Create(p);
            this.Add(p);
        }
        public List<Persona> Read()
        {
            this.Clear();
            this.AddRange(ds.Read());
            return this;
        }
        public List<Persona> Read(int ID)
        {
            this.Clear();
            this.AddRange(ds.Read(ID));
            return this;
        }
        public void Update(Persona p)
        {
            ds.Update(p);
            this.Clear();
            this.AddRange(ds.Read());
        }
        public void Delete(int ID)
        {
            ds.Delete(ID);
            this.Clear();
            this.AddRange(ds.Read());
        }

        public bool Compare(List<Persona> compList)
        {
            bool res = false;
            if (compList.Count != this.Count) res = false;
            else
            {
                res = true;
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].ID != compList[i].ID ||
                        this[i].Fname != compList[i].Fname ||
                        (this[i]).Lname != (compList[i]).Lname ||
                        (this[i]).Age != (compList[i]).Age)
                    {
                        res = false;
                        break;
                    }

                }
            }
            return res;
        }
    }

}
